package com.first.wchat.data;

import java.util.ArrayList;

public class Group {
	
	int id;
	String name;
	ArrayList<User> member;
	UserStateChangeListener mUserListener;
	
	public interface UserStateChangeListener
	{
		public void UserIn(User u);
		public void UserOut(User u);
		
	}
	
	
	public Group(int id,String name)
	{
		this.id = id;
		this.name =name;
	}
	
	public int getID()
	{
		return id;
	}
	
	public String getName()
	{
		return name;
	}
	
	public ArrayList<User> getMember()
	{
		return member;
	}
	
	public synchronized void add(User u)
	{
		if(!member.contains(u))
		{
			member.add(u);
			if(mUserListener!=null)
				mUserListener.UserIn(u);
		}
	}
	
	public synchronized void remove(User u)
	{
		if(member.contains(u))
		{
			member.remove(u);
			if(mUserListener!=null)
				mUserListener.UserOut(u);
		}
	}
}
